<?php
require 'cLib.php';
require 'str.php';
set_time_limit(30);
//ignore_user_abort();

$bduss = 'BDUSS|STOKEN'; //需要BDUSS ，STOKEN 这两个cookie


/*一键签到*/

if($_GET['ac'] == 'sign'){
$url = 'https://tieba.baidu.com/tbmall/onekeySignin1?_=1495376503329';

$header[] = 'Host:tieba.baidu.com';
$header[] = 'X-Requested-With: XMLHttpRequest';
$header[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36';
$header[] = 'Referer: tieba.baidu.com/index.html';

cURL::singleton()->get($url,false,$header)->cookie('r',$bduss)->exec(false);
exit;
}

/*
*$kw 贴吧名
*/
$kw = '南宁'; 

/*
*$fid 贴吧id
*/
$fid = '17107';

$url = 'http://tieba.baidu.com/f?kw='.$kw.'&ie=utf-8&pn=0';

$header[] = 'Host:tieba.baidu.com';
$header[] = 'User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36';

$str = cURL::singleton()->get($url,false,$header)->cookie('r',$bduss)->exec(true);

preg_match_all('#<div class="t_con cleafix">.*<span class="threadlist_rep_num center_text".*title="回复">0</span>.*<a href="/p/(.*)" title=".*" target="_blank" class="j_th_tit ">(.*)</a>#iUs',$str,$p);

//print_r($p[1]);
//print_r($p[2]);

if(empty($p[1])) exit('暂时没有要回复的帖子');

foreach ($p[1] as $value) {
    $data = 'ie=utf-8&kw='.$kw.'&fid='.$fid.'&tid='.$value.'&vcode_md5=&floor_num=1&rich_text=1&tbs=c291db9d2d5310bd1495455992&content='.$x[mt_rand(0,5)].'&basilisk=1&files=[]&mouse_pwd=83,87,83,77,80,86,86,88,104,80,77,81,77,80,77,81,77,80,77,81,77,80,77,81,77,80,77,81,104,80,86,80,89,88,104,80,88,83,81,77,80,81,89,81,14954468943970&mouse_pwd_t=1495446894397&mouse_pwd_isclick=0&__type__=reply';
    
    echo cURL::singleton()->post('http://tieba.baidu.com/f/commit/post/add', $data, false)->cookie('r',$bduss)->exec(false).'<br><br>';
    sleep(2);
  }

    

